/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.service.ro.impl;

import java.util.ArrayList;
import java.util.List;

import com.us.usws.cache.UserCache;
import com.us.usws.common.resourcetree.model.VideoCatTree;
import com.us.usws.dao.BaseVideoCatDAO;
import com.us.usws.model.domain.base.BaseVideoCat;
import com.us.usws.service.ro.BaseVideoCatROService;
import com.us.usws.support.ext.CacheManager;

/**
 * Service RO impl class
 * @author robot
 */
public class BaseVideoCatROServiceImpl implements BaseVideoCatROService {

	/**
	 * DAO instance
	 */
	private BaseVideoCatDAO dao = new BaseVideoCatDAO();

	/**
	 * Get Count.
	 */
	@Override
	public int getTotalCount() {
		return dao.getTotalCount();
	}

	/**
	 * Get all list.
	 */
	@Override
	public List<BaseVideoCat> getAllBaseVideoCats() {
		List<BaseVideoCat> bvcs = dao.getAllBaseVideoCats();
		UserCache userCache = CacheManager.getUserCache();
		
		for(BaseVideoCat bvc:bvcs) {
			bvc.setCreateUserName(userCache.getUserName(bvc.getCreateByUid()));
		}
		return bvcs;
	}

	/**
	 * Get all list by pagination.
	 */
	@Override
	public List<BaseVideoCat> getBaseVideoCats(int start, int end) {
		return dao.getBaseVideoCats(start, end);
	}

	/**
	 * Get BaseVideoCat by primary key.
	 */
	@Override
	public BaseVideoCat getBaseVideoCat(String uid) {
		BaseVideoCat b = dao.getBaseVideoCat(uid);
		return b;
	}

	public List<BaseVideoCat> getRalateCatsByVideoType(int videoTypeId) {
		return dao.getRalateCatsByVideoType(videoTypeId);
	}
	
	/**
	 * get video cat tree
	 */
	public VideoCatTree getVideoCatTree(List<String> rateCats) {
		List<VideoCatTree> videoCatTrees = new ArrayList<VideoCatTree>();
		VideoCatTree root = new VideoCatTree();
		int id = 0;
		root.setText("视频类别");
		root.setId(id);
		root.setChildren(videoCatTrees);
		List<BaseVideoCat> bvcs = dao.getAllBaseVideoCats();
		for (BaseVideoCat bvc : bvcs) {
			VideoCatTree videoCatTree = new VideoCatTree();
			videoCatTree.setId(++id);
			String catUid = bvc.getUid();
			videoCatTree.setCatUid(catUid);
			/*
			 * check has selected cat
			 */
			if (rateCats != null && rateCats.contains(catUid)) {
				videoCatTree.setChecked(true);
			}
			videoCatTree.setText(bvc.getName());
			videoCatTree.setLeaf(true);
			videoCatTrees.add(videoCatTree);
		}
		return root;
	}
}